package com.yicong.taxi.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 作者:CYY
 * 时间:2018/12/3
 */
public class TimeUtils {
    public static String getMin_Sec(){
        Calendar calendar= Calendar.getInstance();
        SimpleDateFormat dateFormat= new SimpleDateFormat("HH:mm:ss");
        return dateFormat.format(calendar.getTime());
    }

    public static String getCurrentTime(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date curDate =  new Date(System.currentTimeMillis());
        return sdf.format(curDate);
    }

    public static String toDateString(long created_at){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        long time = new Long(created_at); //1480428796是unix时间戳，
        return sdf.format(new Date(time));
    }

    public static String toDateString2(long created_at){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        long time = new Long(created_at)*1000L; //1480428796是unix时间戳，
        return sdf.format(new Date(time));
    }

    public static String toDateString4(long created_at){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
        long time = new Long(created_at)*1000L; //1480428796是unix时间戳，
        return sdf.format(new Date(time));
    }

    public static String toDateString3(long created_at){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long time = new Long(created_at)*1000L; //1480428796是unix时间戳，
        return sdf.format(new Date(time));
    }
    //今天的起始时间
    public static long getDateStart(){
        Calendar todayStart = Calendar.getInstance();
        todayStart.set(Calendar.HOUR_OF_DAY, 0);
        todayStart.set(Calendar.MINUTE, 0);
        todayStart.set(Calendar.SECOND, 0);
        todayStart.set(Calendar.MILLISECOND, 0);
        Date startTime = todayStart.getTime();
        return startTime.getTime()/1000;
    }
    //今天的结束时间
    public static long getDateEnd(){
        Calendar todayEnd = Calendar.getInstance();
        todayEnd.set(Calendar.HOUR_OF_DAY, 23);
        todayEnd.set(Calendar.MINUTE, 59);
        todayEnd.set(Calendar.SECOND, 59);
        todayEnd.set(Calendar.MILLISECOND, 999);
        Date todayEndTime = todayEnd.getTime();
        return todayEndTime.getTime()/1000;
    }
    //过去天数
    public static long getPassDates(int days){
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        c.add(Calendar.DATE, days);
        Date date = c.getTime();
        return date.getTime()/1000;
    }
    public static long stringToLong(String str){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long time=0;
        try {
            Date date = format.parse(str);
            time = date.getTime()/1000;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }
}
